import path from "path";

class ConfigManager {
  private configRootPath = "./src/config/";

  getEnvironment(): string {
    const projectConfigFile = path.resolve(
      `${this.configRootPath}project.config.json`
    );

    const projectConfig = require(projectConfigFile);
    return projectConfig.environment;
  }

  private getConfigFile(configName: string) {
    const environment = this.getEnvironment();
    const configFile = path.resolve(
      this.configRootPath,
      `${configName}.${environment}.json`
    );

    return configFile;
  }

  getRedisConfig() {
    const configFile = this.getConfigFile("redis");
    return require(configFile);
  }
}

const configManager = new ConfigManager();
export { configManager };
